@REM 这是一个用于烧录程序的批处理文件，请不要修改！！
@REM 

echo off
cls
chcp 65001
date /t
echo 程序开始执行

setlocal enabledelayedexpansion

@REM 必要的初始化参数,可根据实际情况修改
set TOOL_NAME=STM32_Programmer_CLI.exe
set TOOL_PORT=swd
set TOOL_SPEED=4000

@REM 0x1FFF7590 G0芯片的SN地址
set CHIP_SNADDR=0x1FFF7590
set CHIP_UNRDP=0xAA
set CHIP_RDP=0xBB

@REM app.bin
set APP_FILENAME=system.bin
set APP_BURNADDR=0x8005000

@REM 系统校验参数
set PARAM_FILENAME=param.bin
set PARAM_BURNADDR=0x8004800

@REM 引导程序
set BOOT_FILENAME=boot.bin
set BOOT_BURNADDR=0x8000000

@REM 用户数据
set DATA_FILENAME=data.bin
set DATA_BURNADDR=0x08011000

@REM 命令拼接
set CMDSTR=%TOOL_NAME% -c port=%TOOL_PORT% freq=%TOOL_SPEED% 

echo 获取设备SN号码...
%CMDSTR% -r %CHIP_SNADDR% 12 sn.bin

@REM 等待5秒，防止上一个操作未完成
timeout 2
echo 计算CRC32校验码...
crc32_mpeg22.exe

@REM 命令拼接
set ALLCMDSTR=%CMDSTR%

@REM 解除芯片读保护
set "ALLCMDSTR=%ALLCMDSTR% -rdu -e all"

echo 烧录参数...
@REM %CMDSTR% -w param.bin  0x8004000 -v
set "ALLCMDSTR=%ALLCMDSTR% -w %PARAM_FILENAME%  %PARAM_BURNADDR% -v"

echo 烧录引导程序...
@REM %CMDSTR% -w boot.bin  0x8000000 -v
set "ALLCMDSTR=%ALLCMDSTR% -w %BOOT_FILENAME%  %BOOT_BURNADDR% -v"

echo 烧录应用程序...
@REM %CMDSTR% -w app.bin  0x8004800 -v
set "ALLCMDSTR=%ALLCMDSTR% -w %APP_FILENAME%  %APP_BURNADDR% -v"

@REM echo 烧录用户数据...
@REM %CMDSTR% -w data.bin  0x8004800
set "ALLCMDSTR=%ALLCMDSTR% -w %DATA_FILENAME%  %DATA_BURNADDR% -v"


echo 设置读保护...
@REM %CMDSTR% -ob rdp=0x00
@REM set "ALLCMDSTR=%ALLCMDSTR% -ob rdp=%CHIP_RDP%"

@REM echo 设备重启...
@REM set "ALLCMDSTR=%ALLCMDSTR% -s %BOOT_BURNADDR%"

echo 最终 %ALLCMDSTR%

@REM exit

@REM 执行命令
%ALLCMDSTR%

endlocal

pause